package service.impl.v2;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import dao.v2.ConfigVOMapper;
import service.v2.CacheManagerService;
import service.v2.ConfigService;
import util.ConfUtil;
@Service
public class ConfigServiceImpl implements ConfigService {
	@Autowired
	private ConfigVOMapper dao;
	@Autowired
	private CacheManagerService cacheService;

	@Cacheable(value="ConfigServiceImpl_loadConfig",key="#key")
	public String loadConfig(String key) {
		return dao.loadConfig(key);
	}

	@Override
	public Map getUpdate(String version) {
		return dao.getUpdate(version);
	}

	@Override
	public void updConfValueByKey(String string, String jsonString) {
		dao.updConfValueByKey(string,jsonString);
		cacheService.deleteConf("JS_API_TICKET");
	}

	@Override
	public String getTime() {
		return dao.getTime();
	}
	
	@Override
	public String loadHost() {
		if(ConfUtil.HOST == null){
			ConfUtil.HOST = dao.loadConfig("HOST");
		}
		return ConfUtil.HOST;
	}
	@Override
	public String loadVersion() {
		if(ConfUtil.VERSION == null){
			ConfUtil.VERSION = dao.loadConfig("VERSION");
		}
		return ConfUtil.VERSION;
	}
}
